import resources.RegistNetPropertyBundle;

import registnet.base.summary.delinquency.WarningDelinquency;
import registnet.base.summary.delinquency.WarningDelinquencySource;
import registnet.base.summary.delinquency.ProbationDelinquency;
import registnet.base.summary.delinquency.ProbationDelinquencySource;
import registnet.base.summary.delinquency.DismissalDelinquency;
import registnet.base.summary.delinquency.DismissalDelinquencySource;
import registnet.base.summary.delinquency.PermanentDisqualificationDelinquency;
import registnet.base.summary.delinquency.PermanentDisqualificationDelinquencySource;
import registnet.base.summary.delinquency.IScholarshipDelinquency;
import registnet.base.constituent.Student;
import registnet.base.Grade;
		
import registnet.dao.GradePeer;
import registnet.dao.CoursePeer;
		
import resources.Constants;

/* [start] 	initializes gui variables */
RegistNetPropertyBundle bundle = RegistNetPropertyBundle.getInstance("/resources/registnet");

String _academic_year = bundle.getProperty("registnet.module.summary.macro.delinquency.search.academic_year");
String _semester = bundle.getProperty("registnet.module.summary.macro.delinquency.search.semester");

String _student_number = bundle.getProperty("registnet.module.summary.macro.delinquency.form.student_number");
String _full_name = bundle.getProperty("registnet.module.summary.macro.delinquency.form.full_name");
String _sex = bundle.getProperty("registnet.module.summary.macro.delinquency.form.sex");
String _college = bundle.getProperty("registnet.module.summary.macro.delinquency.form.college");
String _degree_course = bundle.getProperty("registnet.module.summary.macro.delinquency.form.degree_course");
String _delinquency = bundle.getProperty("registnet.module.summary.macro.delinquency.form.delinquency");

/* [end] */		



/* [start]	defines a renderer for the grades */
private class DelinquencyRenderer implements RowRenderer  {
	public void render(Row row, java.lang.Object data) {
		new Label(data[0]).setParent(row);
		new Label(data[1]).setParent(row);
		new Label(data[2]).setParent(row);
		new Label(data[3]).setParent(row);
		new Label(data[4]).setParent(row);
		new Label(data[5]).setParent(row);
	}
}
/* [end] */



/* [start] 	retrieves the grades and places them on the listbox */
void retrieveObjects(){
	Integer semesterValue = Constants.MAP_SEMESTER_KEY.get(semester.getSelectedItem().getLabel());
	Integer yearValue;
	if (semesterValue == Constants.MAP_SEMESTER_KEY.get(Constants.SUMMER))
		yearValue = Integer.parseInt(year2.value);
	else
		yearValue = Integer.parseInt(year1.value);
	
	IScholarshipDelinquency delinquencyList;
	
	if (delinquency_type.getSelectedItem().getLabel().equals(Constants.WARNING))
		delinquencyList = (WarningDelinquency)new WarningDelinquencySource(yearValue, semesterValue).getDelinquencyList();
	else if (delinquency_type.getSelectedItem().getLabel().equals(Constants.PROBATION))
		delinquencyList = (ProbationDelinquency)new ProbationDelinquencySource(yearValue, semesterValue).getDelinquencyList();
	else if (delinquency_type.getSelectedItem().getLabel().equals(Constants.DISMISSAL))
		delinquencyList = (DismissalDelinquency)new DismissalDelinquencySource(yearValue, semesterValue).getDelinquencyList();
	else if (delinquency_type.getSelectedItem().getLabel().equals(Constants.PERMANENT_DISQUALIFICATION))
		delinquencyList = (PermanentDisqualificationDelinquency)new PermanentDisqualificationDelinquencySource(yearValue, semesterValue).getDelinquencyList();	
	
	Iterator iter = delinquencyList.getDelinquencyList().keySet().iterator();
	String[][] listModel = new String[delinquencyList.getDelinquencyList().size()][6];
	int i=0;
	while(iter.hasNext()){
		Student student = iter.next();
		listModel[i][0] = "" + (i + 1);
		listModel[i][1] = student.getStudentNumber();
		listModel[i][2] = student.getLastName() + " " + student.getFirstName() + " " + student.getMiddleName();
		listModel[i][3] = student.getSex();
		listModel[i][4] = student.getCollegeCode();
		listModel[i][5] = student.getDegreeProgram();
		i++;
	}
	
	ListModel strset = new SimpleListModel(listModel);
	contents_win.getFellow("delinquency_g").setModel(strset);
	contents_win.getFellow("delinquency_g").setRowRenderer(new DelinquencyRenderer());
}
/* [end] */



/* [start]	defines a renderer for the grades */
public class SectionRenderer implements ListitemRenderer {
	public void render(Listitem item, java.lang.Object data) {
		new Listcell(data).setParent(item);
	}
}
/* [end] */



/* [start]	automatically updates the 'to' value of academic year based on the
			current 'from' value of the academic year */
private void updateAY(){
	try{
		year2.value = (Integer.parseInt(event.value) + 1).toString();
	}catch(Exception e) {year1.value = null; year2.value = null;}
}
/* [end] */
